package org.travel.app.service.impl;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.travel.app.common.util.InitOrder;
import org.travel.app.entity.Hotel;
import org.travel.app.entity.HotelReservation;
import org.travel.app.mapper.HotelMapper;
import org.travel.app.service.HotelService;

import java.util.List;

/**
 * @author nmm
 * @date 2024-12-2024/12/8
 * @deriction njm......
 */
@Service
@RequiredArgsConstructor
public class HotelServiceImpl implements HotelService {
    /**
     * 酒店业务接口
     */
    private final HotelMapper hotelMapper;

    private final OrderServiceImpl orderService;

    private final InitOrder initOrder;

    /**
     * 添加酒店预约信息
     * @param hotelReservation 酒店预约信息
     */
    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public void addHotelReservation(HotelReservation hotelReservation) {
        hotelMapper.addHotelReservation(hotelReservation);
        //添加酒店预约信息
        orderService.saveOrder(initOrder.createOrder(hotelReservation));
        //生成酒店订单
    }

    @Override
    public PageInfo<Hotel> getHotelList(Hotel hotel,int pageNum, int pageSize) {
        List<Hotel> hotelList = hotelMapper.getHotelList(hotel,pageNum,pageSize);
        return new PageInfo<>(hotelList);
    }


}